/*   1:    */ package com.rinsi.app.zhcx.mkcx;
/*   2:    */ 
/*   3:    */ import com.rinsi.core.contoller.CoreSimpleController;
/*   4:    */ import com.rinsi.core.service.CoreSimpleService;
/*   5:    */ import java.io.BufferedInputStream;
/*   6:    */ import java.io.BufferedOutputStream;
/*   7:    */ import java.io.File;
/*   8:    */ import java.io.FileInputStream;
/*   9:    */ import java.util.HashMap;
/*  10:    */ import java.util.List;
/*  11:    */ import java.util.Map;
/*  12:    */ import javax.servlet.ServletContext;
/*  13:    */ import javax.servlet.http.HttpServletRequest;
/*  14:    */ import javax.servlet.http.HttpServletResponse;
/*  15:    */ import javax.servlet.http.HttpSession;
/*  16:    */ import net.sf.jxls.transformer.XLSTransformer;
/*  17:    */ import org.springframework.beans.factory.annotation.Autowired;
/*  18:    */ import org.springframework.stereotype.Controller;
/*  19:    */ import org.springframework.ui.ModelMap;
/*  20:    */ import org.springframework.web.bind.annotation.RequestMapping;
/*  21:    */ 
/*  22:    */ @Controller
/*  23:    */ @RequestMapping({"/zhcx/mkcx"})
/*  24:    */ public class ZhcxMkcxController
/*  25:    */   extends CoreSimpleController
/*  26:    */ {
/*  27:    */   @Autowired
/*  28:    */   private ZhcxMkcxService zhcxService;
/*  29:    */   
/*  30:    */   @RequestMapping({"/outData"})
/*  31:    */   public void outData(ModelMap model, HttpServletRequest request, HttpServletResponse response)
/*  32:    */   {
/*  33: 96 */     String tplPath = request.getSession().getServletContext().getRealPath("") + "/tpl/tpKjxx.xls";
/*  34:    */     
/*  35: 98 */     String filepath = request.getSession().getServletContext().getRealPath("") + "/temp/" + request.getParameter("UID");
/*  36:    */     
/*  37:100 */     new File(filepath).mkdirs();
/*  38:    */     
/*  39:102 */     String excelFileName = "煤矿基本情况信息表.xls";
/*  40:    */     
/*  41:104 */     Map<String, Object> beans = new HashMap();
/*  42:    */     
/*  43:106 */     List<Map<String, Object>> list = this.zhcxService.outData(model);
/*  44:    */     
/*  45:108 */     beans.put("datas", list);
/*  46:    */     
/*  47:110 */     XLSTransformer transformer = new XLSTransformer();
/*  48:    */     
/*  49:112 */     BufferedOutputStream bos = null;
/*  50:    */     try
/*  51:    */     {
/*  52:116 */       transformer.transformXLS(tplPath, beans, filepath + "/" + excelFileName);
/*  53:    */       
/*  54:118 */       BufferedInputStream bis = new BufferedInputStream(new FileInputStream(filepath + "/" + excelFileName));
/*  55:    */       
/*  56:120 */       byte[] buff = new byte[2048];
/*  57:    */       
/*  58:122 */       response.setContentType("text/html;charset=UTF-8");
/*  59:    */       
/*  60:124 */       request.setCharacterEncoding("UTF-8");
/*  61:    */       
/*  62:126 */       response.setContentType("application/x-msdownload;");
/*  63:    */       
/*  64:128 */       response.setHeader("Content-disposition", "attachment; filename=" + new String(excelFileName.getBytes("gb2312"), "iso-8859-1"));
/*  65:    */       
/*  66:130 */       bos = new BufferedOutputStream(response.getOutputStream());
/*  67:    */       int bytesRead;
/*  68:134 */       while (-1 != (bytesRead = bis.read(buff, 0, buff.length)))
/*  69:    */       {
/*  70:    */         //int bytesRead;
/*  71:136 */         bos.write(buff, 0, bytesRead);
/*  72:    */       }
/*  73:140 */       bos.flush();
/*  74:    */       
/*  75:142 */       bos.close();
/*  76:    */     }
/*  77:    */     catch (Exception e)
/*  78:    */     {
/*  79:146 */       e.printStackTrace();
/*  80:    */     }
/*  81:    */   }
/*  82:    */   
/*  83:    */   public CoreSimpleService servce()
/*  84:    */   {
/*  85:156 */     return this.zhcxService;
/*  86:    */   }
/*  87:    */ }


/* Location:           D:\Users\Desktop\shanxi\项目\sxazmis\WEB-INF\classes\
 * Qualified Name:     com.rinsi.app.zhcx.mkcx.ZhcxMkcxController
 * JD-Core Version:    0.7.0.1
 */